package com.ruoyi.clothing.service.impl;

import java.util.HashMap;
import java.util.List;

import com.ruoyi.clothing.domain.User;
import com.ruoyi.clothing.domain.vo.AddBuild;
import com.ruoyi.clothing.mapper.UserMapper;
import com.ruoyi.clothing.service.IUserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.ruoyi.clothing.mapper.SysBuildMapper;
import com.ruoyi.clothing.domain.SysBuild;
import com.ruoyi.clothing.service.ISysBuildService;

/**
 * 身材管理Service业务层处理
 *
 * @author weh
 * @date 2024-01-18
 */
@Service
public class SysBuildServiceImpl implements ISysBuildService
{
    @Autowired
    private SysBuildMapper sysBuildMapper;

    @Autowired
    private UserMapper userMapper;

    /**
     * 查询身材管理
     *
     * @param id 身材管理主键
     * @return 身材管理
     */
    @Override
    public SysBuild selectSysBuildById(Integer id)
    {
        return sysBuildMapper.selectSysBuildById(id);
    }

    /**
     * 查询身材管理列表
     *
     * @param sysBuild 身材管理
     * @return 身材管理
     */
    @Override
    public List<SysBuild> selectSysBuildList(SysBuild sysBuild)
    {
        return sysBuildMapper.selectSysBuildList(sysBuild);
    }

    /**
     * 新增身材管理
     *
     * @param sysBuild 身材管理
     * @return 结果
     */
    @Override
    public int insertSysBuild(SysBuild sysBuild)
    {
        return sysBuildMapper.insertSysBuild(sysBuild);
    }

    /**
     * 修改身材管理
     *
     * @param sysBuild 身材管理
     * @return 结果
     */
    @Override
    public int updateSysBuild(SysBuild sysBuild)
    {
        return sysBuildMapper.updateSysBuild(sysBuild);
    }

    /**
     * 批量删除身材管理
     *
     * @param ids 需要删除的身材管理主键
     * @return 结果
     */
    @Override
    public int deleteSysBuildByIds(Integer[] ids)
    {
        return sysBuildMapper.deleteSysBuildByIds(ids);
    }

    /**
     * 删除身材管理信息
     *
     * @param id 身材管理主键
     * @return 结果
     */
    @Override
    public int deleteSysBuildById(Integer id)
    {
        return sysBuildMapper.deleteSysBuildById(id);
    }

    @Override
    public List<SysBuild> selectBuildListById(Long id) {
        return sysBuildMapper.selectBuildListById(id);
    }

    @Override
    public int insertBuild(AddBuild data) {
        User user = userMapper.selectUserByUserName(data.getUsername());
        Long id = user.getId();
        HashMap<String , Object> map = new HashMap<>();
        map.put("b_name",data.getbName());
        map.put("b_sex",data.getbSex());
        map.put("b_height",data.getbHeight());
        map.put("b_weight",data.getbWeight());
        map.put("b_bust",data.getbBust());
        map.put("b_girth",data.getbGirth());
        map.put("b_owner",id);
        sysBuildMapper.insertBuild(map);
        return 1;
    }

    @Override
    public int deleteBuild(Integer id) {
        return sysBuildMapper.deleteBuild(id);
    }
}
